package com.supermarket.api.web;

import com.supermarket.api.bean.category.ProductReq;
import com.supermarket.api.common.BaseResponse;
import com.supermarket.api.entity.CategoryEntity;
import com.supermarket.api.entity.ProductEntity;
import com.supermarket.api.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 分类接口
 * @author 李其伟
 * @date 2023/10/17
 */
@Controller
@RequestMapping("/category")
public class CategoryController {

    /**
     * 分类服务层
     */
    @Autowired
    private CategoryService categoryService;

    @ResponseBody
    @GetMapping("/all")
    public String all(){
        List<CategoryEntity> list = categoryService.list();
        return BaseResponse.successJson(list);
    }

    @ResponseBody
    @GetMapping("/product")
    public String product(ProductReq req){
        Page<ProductEntity> page = categoryService.product(req);
        return BaseResponse.successJson(page);
    }
}
